/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { ModalForm, ProFormText, ProFormDigit } from '@ant-design/pro-form';
import { addInvoice } from '@/services/Financial';
import { message } from 'antd';

interface KbAddModal {
  children: JSX.Element;
  actionRef: any;
  queryData: { id: string; kb_id: string };
}
const Index = ({ queryData, children, actionRef }: KbAddModal) => {
  const onSubmit = async (values: { invoice_amount: string; invoice_title: string }) => {
    const { code, msg } = await addInvoice({ ...queryData, ...values });
    if (code == 0) {
      actionRef.current?.reload();
      message.success(msg);
      return true;
    } else {
      message.error(msg);
      return false;
    }
  };

  return (
    <ModalForm
      title='添加开票信息'
      width={500}
      trigger={children}
      layout='horizontal'
      modalProps={{
        destroyOnClose: true,
      }}
      onFinish={onSubmit}
    >
      <ProFormDigit
        label='开票金额'
        name='invoice_amount'
        style={{ width: '100%' }}
        fieldProps={{ precision: 2 }}
        rules={[
          {
            required: true,
            message: '请输入开票金额',
          },
        ]}
      />
      <ProFormText
        label='开票抬头'
        name='invoice_title'
        style={{ width: '100%' }}
        fieldProps={{
          maxLength: 80,
        }}
      />
    </ModalForm>
  );
};

export default Index;
